<?php
/**
 * Smart Library - Smart Framework
 * http://smart-framework.highet.eu
 *
 * @category   SmartL
 * @package    SmartL_Zend
 * @subpackage View
 * @copyright  Copyright (c) 2005-2008 Smart Framework team - Stepan Sindelar, Vojtech Vit
 * @license    http://www.opensource.org/licenses/bsd-license.php	New BSD License
 */

/**
 * @see Zend_View
 */
require_once 'Zend/View.php';

/**
 * @see SmartL_Zend_View_Helper_Url
 */
require_once 'SmartL/Zend/View/Helper/Url.php';

/**
 * Smart Library custom view class.
 * 
 * SmartL supports multiple template system and this view class does all things 
 * neccessary to support it (like setting correct paths, for example).
 * 
 * @todo 26 Predelani na pool by mohlo snizit pocet vytvarenych instanci, kterych je dost.
 *    
 * @package SmartL_Zend
 * @subpackage View
 */
class SmartL_Zend_View extends Zend_View {
	/**
	 * Encoding to use in escaping mechanisms; Smart Library default is UTF-8
	 * 
	 * @var string
	 */
	private $_encoding = 'UTF-8';
	
	/**
	 * Given a base path, sets the script, helper, and filter paths relative to it
	 *
	 * Assumes a directory structure of:
	 * <code>
	 * basePath/
	 *     Script/
	 *     Helper/
	 *     Filter/
	 * </code>
	 *
	 * @param  string $path
	 * @param  string $prefix Prefix to use for helper and filter paths
	 * @param string $templateName Used template name
	 * @return Zend_View_Abstract
	 */
	public function setBasePath($path, $classPrefix = "Zend_View", $templateName = "") {
		$ds = DIRECTORY_SEPARATOR;
		if (is_null ( $classPrefix )) {
			$classPrefix = "Zend_View";
		}
		if ($templateName !== "") {
			$templateName .= $ds;
		}
		
		$path = rtrim ( $path, '/\\' );
		$path .= $ds;
		$classPrefix = rtrim ( $classPrefix, '_' ) . '_';
		
		$this->setScriptPath ( $path . $templateName . 'Script' );
		$this->setHelperPath ( $path . $templateName . 'Helper', $classPrefix . 'Helper' );
		$this->setFilterPath ( $path . $templateName . 'Filter', $classPrefix . 'Filter' );
		// @todo 22 : Možnost to v konfiguraci vypnout.        
		$this->addHelperPath ( "SmartL/Zend/View/Helper", "SmartL_Zend_View_Helper_" );
		
		// @todo : Toto bylo přidáno jako nouzovka!! Je třeba opravit!! PluginLoader, který volá (asi) View, nedostal (asi včas?) při inicializaci View pomocí Zend_Dojo::enableView($view) cestu k Dojo View Helperům. 
		$this->addHelperPath ( "Zend/Dojo/View/Helper", "Zend_Dojo_View_Helper_" );
		return $this;
	}
	
	/**
	 * Given a base path, add script, helper, and filter paths relative to it
	 *
	 * Assumes a directory structure of:
	 * <code>
	 * basePath/
	 *     Script/
	 *     Helper/
	 *     Filter/
	 * </code>
	 *
	 * @param  string $path
	 * @param  string $prefix Prefix to use for helper and filter paths
	 * @return SmartL_Zend_View
	 */
	public function addBasePath($path, $classPrefix = 'Zend_View', $templateName = "") {
		$ds = DIRECTORY_SEPARATOR;
		
		if (is_null ( $classPrefix )) {
			$classPrefix = "Zend_View";
		}
		if ($templateName !== "") {
			$templateName .= $ds;
		}
		
		$path = rtrim ( $path, '/\\' );
		$path .= $ds;
		$classPrefix = rtrim ( $classPrefix, '_' ) . '_';
		
		$this->addScriptPath ( $path . $templateName . 'Script' );
		$this->addHelperPath ( $path . $templateName . 'Helper', $classPrefix . 'Helper' );
		$this->addFilterPath ( $path . $templateName . 'Filter', $classPrefix . 'Filter' );
		return $this;
	}
}